package com.lumacong.websocket.util;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CaiJian {
    public String screenShots(String path) {
        String nowtime = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());

        DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        Calendar calendar = Calendar.getInstance();
        String dateName = df.format(calendar.getTime());
        String imgName =   nowtime + ".png";
        try {
            // 获取屏幕尺寸
            // 创建需要截取的矩形区域
            Rectangle rect = new Rectangle(664, 205, 411, 750);
            BufferedImage bufImage = new Robot().createScreenCapture(rect);
            ImageIO.write(bufImage, "PNG", new File(path+imgName));
        } catch (AWTException e) {
            imgName = null;
            e.printStackTrace();
        } catch (IOException e) {
            imgName = null;
            e.printStackTrace();
        } finally {
            return imgName;
        }
    }
}
